package com.woniuxy.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.woniuxy.entity.Role;

@Mapper
public interface RoleMapper {
	//查询所有角色
	@Select("select * from t_role")
	public List<Role> findAllRole();
	//根据角色id查询权限id
	@Select("select pid from t_role_permission where rid=#{rid}")
	public List<Integer>findPidByRid(int rid);
	//根据权限id权限name
	@Select("select pname from t_permission where pid=#{pid}")
	public String findPnameByPid(int pid);
	//根据状态查询角色
	@Select("select * from t_role where status=#{status}")
	public List<Role>findRoleByStatus(int status);
	//模糊查询
	@Select("select * from t_role where rname like CONCAT('%',#{words},'%') or rcode like CONCAT('%',#{words},'%')")
	public List<Role>findRoleByWords(String words);
	//新建角色
	@Insert("insert into t_role values(default,#{rname},#{rcode},#{status},#{description},#{ctime})")
	public int insertRole(Role role);
	//删除角色
	@Delete("delete from t_role where rid=#{rid}")
	public int delByRid(int rid);
}
